Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ServiceWorker scope with BASE_PATH. #6935

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hangst
Copy link

@hangst hangst commented Aug 30, 2024

When BASE_PATH is specified to host UI in subpath, ServiceWorkers refuse to work due to mismatching scope. This can be verified through error logs in Chrome devtools on landing page.

Closes #

Checklist

Authors and Reviewer(s), please verify the following:

  • A PR description, regardless of the triviality of this change, that communicates the value of this PR
  • Well-formatted conventional commit messages that provide context into the change
  • Documentation updated or issue created (provide link to issue/PR)
  • Signed CLA (if not already signed)

When BASE_PATH is specified to host UI in subpath, ServiceWorkers refuse to work due to mismatching scope. This can be verified through error logs in Chrome devtools on landing page.
@hangst hangst requested review from a team as code owners August 30, 2024 06:29
@hangst hangst requested a review from david-rusnak August 30, 2024 06:29
@wdoconnell
Copy link
Contributor

Hello - in order to resolve a PR, we need the following information to identify the error it is intended to resolve.

Can you tell us:
What happened when the error occurred?
Can you (and how can we) reproduce it?
Are you using our Cloud or OSS product?
What version?
What browser are you using?

Thanks for using InfluxDB.

@hangst
Copy link
Author

hangst commented Sep 10, 2024

Hi,

What happened when the error occurred?

This error is specfic to users compiling the UI with BASE_PATH. Error messages show up in Chrome devtools preventing ServiceWorker to work due to mismatching BASE_PATH scope. This does not interfer with basic features, but should cause issues with components requiring ServiceWorker.

Can you (and how can we) reproduce it?

  1. Compile branch OSS-v2.7.9 with non-empty BASE_PATH, for example BASE_PATH=/influx.
set -e
# Compile UI with subdir
git clone --depth 1 https://github.com/influxdata/ui --branch OSS-v2.7.9 ||:
docker build ui -f ui/docker/Dockerfile.chronograf.prod --tag=influx-ui \
    --build-arg=BASE_PATH=/influx \
    --build-arg=API_BASE_PATH=/influx
# Run frontend
docker run -d -p 9999:9999 influx-ui
  1. Serve the compiled UI behind an NGINX reverse proxy. (Backend is unnecessary to reproduce this error.)
events {
    worker_connections  1024;
}
http {
    server {
        listen 80;
        # Backend
        location ~ ^/influx/(api/.*|health) {
            proxy_cookie_path ~*^/api /influx/api;
            set $upstream http://127.0.0.1:8086/$1$is_args$args;
            proxy_pass $upstream;
        }
        # Frontend
        location ~ ^/influx/(.*) {
            set $upstream http://127.0.0.1:9999/$1$is_args$args;
            proxy_pass $upstream;
        }
    }
}
# Run backend
docker run -d -p 8086:8086 -e INFLUXD_UI_DISABLED=true influxdb:latest
# Run reverse proxy
docker run --rm --network=host -v $PWD/nginx.conf:/etc/nginx/nginx.conf:ro nginx \
    nginx -g "daemon off;" -c /etc/nginx/nginx.conf
  1. Visit localhost/influx/ with Chrome devtools, reload the page, look for ServiceWorker related errors.

Screenshot from 2024-09-10 12-18-15

Are you using our Cloud or OSS product?

OSS.

What version?

v2.7.9.

What browser are you using?

Google Chrome 64-bit official build v128.0.6613.119, on Debian 12 Bookworm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants